import { Body, Controller, Get, Param, ParseIntPipe, Post, Query, UseGuards } from '@nestjs/common';
import { ArticleTagService } from '@/modules/article/article_tag/tag.service';
import {
  CreateTagDto,
  DeleteTagDto,
  QueryTagDto,
  UpdateTagDto,
} from '@/modules/article/article_tag/dto/dto';
import { QueryListDto } from '@/modules/article/dto/dto';
import { AuthGuard } from '@nestjs/passport';

@Controller('article/tag')
export class ArticleTagController {
  constructor(private readonly articleTagService: ArticleTagService) {}

  // 获取标签总数
  @Get('/total')
  async tagTotal() {
    return await this.articleTagService.tagTotal();
  }

  // 获取标签的文章总数
  @Get(':id/article/total')
  async tagArticleTotal(@Param('id', ParseIntPipe) id: number) {
    return await this.articleTagService.tagArticleTotal(id);
  }

  // 按条件对象查询标签列表
  @UseGuards(AuthGuard('jwt'))
  @Get('/query')
  async articleQuery(@Query() data: QueryListDto) {
    return await this.articleTagService.articleTagQuery(data);
  }

  @Get('/list')
  async tagList(@Query() data: QueryTagDto) {
    return await this.articleTagService.tagList(data);
  }

  @Get(':id')
  async tagFindOne(@Param('id', ParseIntPipe) id: number) {
    return await this.articleTagService.tagFindOne(id);
  }

  // 按标签id获取文章列表
  @Get(':id/article')
  async tagArticle(@Query() data: QueryTagDto, @Param('id', ParseIntPipe) id: number) {
    return await this.articleTagService.tagArticle(data, id);
  }

  // 创建标签
  @UseGuards(AuthGuard('jwt'))
  @Post('/create')
  async createTag(@Body() data: CreateTagDto) {
    return await this.articleTagService.createTag(data);
  }

  // 更新标签
  @UseGuards(AuthGuard('jwt'))
  @Post('/update/:id')
  async updateTag(@Param('id', ParseIntPipe) id: number, @Body() data: UpdateTagDto) {
    return await this.articleTagService.updateTag(id, data);
  }

  // 批量删除标签
  @UseGuards(AuthGuard('jwt'))
  @Post('/remove')
  async removeTag(@Body() data: DeleteTagDto) {
    return await this.articleTagService.removeTag(data);
  }

  // 按id删除标签
  @UseGuards(AuthGuard('jwt'))
  @Post('/remove/:id')
  async removeTagOne(@Param('id', ParseIntPipe) id: number) {
    return await this.articleTagService.removeTagOne(id);
  }
}
